
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <link rel="stylesheet" href="/static/component/pear/css/pear.css" />
</head>
<body>
<form class="layui-form" action="">
    <input type="hidden" name="article_id" value="{$info['article_id']}"/>
    <div class="mainBox">
        <div class="main-container">
            <div class="layui-form-item">
                <label class="layui-form-label">标题</label>
                <div class="layui-input-block">
                    <input type="text" maxlength="30" name="title" lay-verify="required" placeholder="标题" autocomplete="off" class="layui-input" value="{$info['title']}">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">所属栏目</label>
                <div class="layui-input-block">
                    <div id="demo1" class="xm-select-demo" name="parent_id"></div>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">描述</label>
                <div class="layui-input-block">
                    <textarea lay-verify="required" placeholder="描述" autocomplete="off" class="layui-input" name="desc" style="height: 150px">{$info['desc']}</textarea>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">作者</label>
                <div class="layui-input-block">
                    <input type="text" maxlength="30" name="author" lay-verify="required" placeholder="作者" autocomplete="off" class="layui-input" value="{$info['author']}">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">发表时间</label>
                <div class="layui-input-block">
                    <input type="text" maxlength="30" name="pub_time" lay-verify="required" placeholder="发表时间" autocomplete="off" class="layui-input" value="{$info['pub_time']}" id="pub_time">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">内容</label>
                <div class="layui-input-block">
                    <textarea name="content" id="edit" cols="30" rows="10">{$info['content']}</textarea>
                </div>
            </div>
        </div>
    </div>
    <div class="bottom">
        <div class="button-container">
            <button type="submit" class="layui-btn layui-btn-normal layui-btn-sm" lay-submit="" lay-filter="save">
                <i class="layui-icon layui-icon-ok"></i>
                提交
            </button>
            <button type="reset" class="layui-btn layui-btn-primary layui-btn-sm">
                <i class="layui-icon layui-icon-refresh"></i>
                重置
            </button>
        </div>
    </div>
</form>
<script src="/static/component/layui/layui.js"></script>
<script src="/static/component/pear/pear.js"></script>
<script src="/static/component/select/xm-select.js"></script>
<script>
    layui.use(['form', 'jquery', 'tinymce', 'laydate'], function(){
        let tinymce = layui.tinymce;
        let form = layui.form;
        let $ = layui.jquery;
        let laydate = layui.laydate;

        laydate.render({
            elem: "#pub_time",
        })

        var edit = tinymce.render({
            elem: "#edit",
            height: 400,
            images_upload_url: '{$Request.root}/admin.upload/doUpload'
        });

        form.on('submit(save)', function(data){

            data.field.content = edit.getContent();

            $.ajax({
                data:JSON.stringify(data.field),
                dataType:'json',
                contentType:'application/json',
                type:'post',
                success:function(res){
                    //判断有没有权限
                    if(res && res.code==999){
                        layer.msg(res.msg, {
                            icon: 5,
                            time: 2000,
                        })
                        return false;
                    } else if(res.code == 0) {
                        layer.msg(res.msg,{icon:1,time:1000},function(){
                            parent.layer.close(parent.layer.getFrameIndex(window.name));//关闭当前页
                            parent.initTable();
                        });
                    }else{
                        layer.msg(res.msg,{icon:2,time:1000});
                    }
                }
            })
            return false;
        });
    })

    var select = xmSelect.render({
        el: '#demo1',
        model: { label: { type: 'text' } },
        radio: true,
        clickClose: true,
        tree: {
            show: true,
            strict: false,
            expandedKeys: true,
        },
        height: 'auto',
        data(){
            return {$cate|raw}
        }
    })

    select.setValue([
        {$default|raw}
    ], null, true)
</script>
</body>
</html>